package studentfunction;

import student.StudenList;
import student.Student;

import java.util.Scanner;

public class FindFunction implements IFunction{
    @Override
    public void work(StudenList studenList) {
        System.out.println("查找学生！");
        System.out.println("请输入学生姓名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int currentSize = studenList.getUsedsize();//获取当前学生数量
        for (int i = 0; i < currentSize; i++) {
            Student student = studenList.getStudent(i);//遍历数组，找到学生
            if(student.getName().equals(name)) {//相等则输出学生信息
                System.out.print("找到了学生：");
                System.out.println(student);
                return;
            }
        }
        System.out.println("没有这位学生！");

    }
}
